package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmMaterialDto;
import com.heima.wemedia.entity.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author RMY
 * @Date 2021/11/27 15:30
 * @Version 1.0
 */
@RestController
public class MaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 上传文章素材
     * @param multipartFile
     * @return
     */
    @PostMapping("/api/v1/material/upload_picture")
    public ResponseResult<String> uploadPic(@RequestParam MultipartFile multipartFile){
        return ResponseResult.ok(wmMaterialService.uploadPicture(multipartFile));
    }

    /**
     * 分页查询素材信息
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/material/list")
    public PageResult<WmMaterial> findByPage(@RequestBody WmMaterialDto dto){
        return wmMaterialService.findByPage(dto);
    }
}
